package com.imyours.webservice.services;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import com.imyours.model.user.UserEntity;
import com.imyours.users.session.UserSessionManager;
import com.imyours.webservice.service.Context;
import com.imyours.webservice.service.ContextService;
import com.imyours.webservice.services.annotation.Service;
@Service(name="userInfo")
public class UserInfo extends ContextService {

	public UserInfo(Context context) {
		super(context);
	}

	public void execute() {
		String sessionId = context.getParameter().get("sessionId");
		if(sessionId!=null){
			UserEntity user = UserSessionManager.getInstance().getUser(sessionId);
			if(user!=null){
				JSONObject jo = JSONObject.fromObject(user);
				jo.remove("id");
				jo.remove("password");
				Map<String,Object> result = new HashMap<String, Object>();
				result.put("user", jo);
				context.setResult(result);
				context.success();
			}else{
				context.fail(2, "invalidate sessionId");
			}
		}
		
		
	}

}
